package com.android.Bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.android.DBTools.ADUS;
import com.android.DBTools.DBConnection;
import com.android.ObjectBean.ServerRecordObjectList;

import net.sf.json.JSONArray;

public class ServerRecordBean {
	// 插入服务记录
	public void serverRecordInsert(String serverTitle, String serverContent)
			throws ClassNotFoundException, SQLException {
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String serverDate = simpleDateFormat.format(date);
		String sql = "INSERT INTO serverrecord (serverID,serverTitle,serverContent,serverDate)" + "VALUES(NULL,\""
				+ serverTitle + "\",\"" + serverContent + "\",\"" + serverDate + "\");";
		ADUS.insertData(sql);
		DBConnection.closeCon();
	}

	// 查看服务记录
	public String serverRecordSelect() throws ClassNotFoundException, SQLException {
		String sql = "SELECT * FROM serverrecord";
		ResultSet rs = ADUS.selectData(sql);
		List<ServerRecordObjectList> list = new ArrayList<ServerRecordObjectList>();
		while (rs.next()) {
			ServerRecordObjectList sList = new ServerRecordObjectList();
			sList.setServerID(rs.getString(rs.findColumn("serverID")));
			sList.setServerTitle(rs.getString(rs.findColumn("serverTitle")));
			sList.setServerContent(rs.getString(rs.findColumn("serverContent")));
			sList.setServerDate(rs.getString(rs.findColumn("serverDate")));
			list.add(sList);
		}
		JSONArray json = JSONArray.fromObject(list);
		return json.toString();
	}
}
